class ChangeBookmarksPageId < ActiveRecord::Migration
  def self.up
    Bookmark.find(:all).each do |bookmark|
      bookmark.update_attribute :page_id, Page.find(bookmark.page_id).page_number
    end
    rename_column :bookmarks, :page_id, :page_number
  end

  def self.down
    Bookmark.find(:all).each do |bookmark|
      bookmark.update_attribute :page_number, bookmark.book.pages[bookmark.page_number+1].id
    end
    rename_column :bookmarks, :page_number, :page_id
  end
end
